#include <my/Time/StopWatch.h>

namespace my {

    StopWatch::StopWatch(bool initrunning) : _buffer(0.f), _running(initrunning)
    {
        //ctor
    }

    StopWatch::~StopWatch()
    {
        //dtor
    }

    float StopWatch::getElapsedTime() const
    {
        if(_running)
            return (_buffer + _clock.GetElapsedTime()) / 1000.f;

        return _buffer / 1000.f;
    }

    bool StopWatch::isRunning() const
    {
        return _running;
    }

    void StopWatch::start()
    {
        if(!_running)
        {
            _running = true;
            _clock.Reset();
        }
    }

    void StopWatch::stop()
    {
        if(_running)
        {
            _running = false;
            _buffer += _clock.GetElapsedTime() / 1000.f;
        }
    }

    void StopWatch::reset(bool stillrunning)
    {
        _buffer = 0.f;
        _running = stillrunning;
        _clock.Reset();
    }


} // namespace
